package com.ruoyi.web.controller.system;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.service.IFormColumnService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FormDefine;
import com.ruoyi.system.service.IFormDefineService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单定义Controller
 *
 * @author ruoyi
 * @date 2023-11-16
 */
@RestController
@RequestMapping("/system/formDefine")
public class FormDefineController extends BaseController
{
    @Autowired
    private IFormDefineService formDefineService;



    /**
     * 查询单定义列表
     */
    @PreAuthorize("@ss.hasPermi('system:define:list')")
    @GetMapping("/list")
    public TableDataInfo list(FormDefine formDefine)
    {
        startPage();
        List<FormDefine> list = formDefineService.list();
        return getDataTable(list);
    }

    /**
     * 导出单定义列表
     */
    @PreAuthorize("@ss.hasPermi('system:define:export')")
    @Log(title = "单定义", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FormDefine formDefine)
    {
        List<FormDefine> list = formDefineService.list();
        ExcelUtil<FormDefine> util = new ExcelUtil<FormDefine>(FormDefine.class);
        util.exportExcel(response, list, "单定义数据");
    }

    /**
     * 获取单定义详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:define:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(formDefineService.getById(id));
    }

    /**
     * 新增单定义
     */
    @PreAuthorize("@ss.hasPermi('system:define:add')")
    @Log(title = "单定义", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FormDefine formDefine)
    {
        return toAjax(formDefineService.saveFormDesc(formDefine));
    }

    /**
     * 修改单定义
     */
    @PreAuthorize("@ss.hasPermi('system:define:edit')")
    @Log(title = "单定义", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FormDefine formDefine)
    {
        return toAjax(formDefineService.updateFormDesc(formDefine));
    }

    /**
     * 删除单定义
     */
    @PreAuthorize("@ss.hasPermi('system:define:remove')")
    @Log(title = "单定义", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(formDefineService.removeByIds(Arrays.asList(ids)));
    }
}
